```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring Bean作用域详解 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.8;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .scope-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .code-block {
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-radius: 6px;
            font-family: 'Courier New', Courier, monospace;
        }
        .icon-circle {
            width: 60px;
            height: 60px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 20px;
            font-size: 24px;
            color: white;
        }
        .hover-grow {
            transition: all 0.3s ease;
        }
        .hover-grow:hover {
            transform: scale(1.05);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4">
        <div class="container mx-auto max-w-5xl text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6">深入理解Spring Bean作用域</h1>
            <p class="text-xl md:text-2xl opacity-90 mb-8">掌握Spring框架中Bean生命周期的核心概念</p>
            <div class="w-20 h-1 bg-white bg-opacity-50 mx-auto mb-10"></div>
            <p class="text-lg max-w-2xl mx-auto opacity-80">
                Bean作用域定义了在Spring容器中创建的Bean实例的生命周期和可见范围，是构建健壮Spring应用的基础知识。
            </p>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-16">
        <!-- Introduction -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">Bean作用域概述</h2>
            <p class="text-lg text-gray-700 mb-8">
                在Spring框架中，Bean的作用域决定了Bean实例的生命周期和可见范围。Spring提供了多种作用域选项，每种都适用于不同的应用场景。选择合适的作用域可以优化资源使用，确保线程安全，并满足特定的业务需求。
            </p>
            
            <!-- Visualization -->
            <div class="bg-white rounded-xl shadow-lg p-6 mb-12 hover-grow">
                <div class="mermaid">
                    graph TD
                        A[Spring Bean] --> B(Singleton)
                        A --> C(Prototype)
                        A --> D(Request)
                        A --> E(Session)
                        A --> F(Global Session)
                        A --> G(Custom)
                        B --> H[整个应用程序共享一个实例]
                        C --> I[每次请求创建新实例]
                        D --> J[每个HTTP请求创建新实例]
                        E --> K[每个用户会话创建新实例]
                        F --> L[Portlet环境全局会话]
                        G --> M[自定义作用域实现]
                </div>
            </div>
        </section>

        <!-- Scope Details -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-10 text-gray-800">六大Bean作用域详解</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- Singleton -->
                <div class="bg-white rounded-lg shadow-md p-6 scope-card transition-all duration-300">
                    <div class="icon-circle bg-blue-500">
                        <i class="fas fa-cube"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-center text-gray-800">Singleton (单例)</h3>
                    <div class="bg-blue-50 p-4 rounded-lg mb-4">
                        <p class="text-blue-800">在整个应用程序中只创建一个Bean实例，所有请求都返回同一个实例。</p>
                    </div>
                    <ul class="text-gray-700 space-y-2 mb-4">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>Spring默认作用域</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>适用于无状态的Bean</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>线程安全问题需要注意</span>
                        </li>
                    </ul>
                    <div class="code-block p-4 text-sm overflow-x-auto">
                        &lt;bean id="exampleBean" class="..." scope="singleton"/&gt;
                    </div>
                </div>
                
                <!-- Prototype -->
                <div class="bg-white rounded-lg shadow-md p-6 scope-card transition-all duration-300">
                    <div class="icon-circle bg-purple-500">
                        <i class="fas fa-clone"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-center text-gray-800">Prototype (原型)</h3>
                    <div class="bg-purple-50 p-4 rounded-lg mb-4">
                        <p class="text-purple-800">每次请求该Bean时都会创建一个新的实例。</p>
                    </div>
                    <ul class="text-gray-700 space-y-2 mb-4">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>适用于需要独立状态的Bean</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>Spring不管理完整的生命周期</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>客户端需要负责清理</span>
                        </li>
                    </ul>
                    <div class="code-block p-4 text-sm overflow-x-auto">
                        @Scope("prototype")<br>
                        public class ExampleBean { ... }
                    </div>
                </div>
                
                <!-- Request -->
                <div class="bg-white rounded-lg shadow-md p-6 scope-card transition-all duration-300">
                    <div class="icon-circle bg-green-500">
                        <i class="fas fa-globe"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-center text-gray-800">Request (请求)</h3>
                    <div class="bg-green-50 p-4 rounded-lg mb-4">
                        <p class="text-green-800">每个HTTP请求都会创建一个新的Bean实例。</p>
                    </div>
                    <ul class="text-gray-700 space-y-2 mb-4">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>仅适用于Web应用</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>同一次请求内共享实例</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>请求结束后实例被销毁</span>
                        </li>
                    </ul>
                    <div class="code-block p-4 text-sm overflow-x-auto">
                        @Controller<br>
                        @Scope(value = WebApplicationContext.SCOPE_REQUEST, <br>
                        &nbsp;&nbsp;proxyMode = ScopedProxyMode.TARGET_CLASS)
                    </div>
                </div>
                
                <!-- Session -->
                <div class="bg-white rounded-lg shadow-md p-6 scope-card transition-all duration-300">
                    <div class="icon-circle bg-yellow-500">
                        <i class="fas fa-user"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-center text-gray-800">Session (会话)</h3>
                    <div class="bg-yellow-50 p-4 rounded-lg mb-4">
                        <p class="text-yellow-800">每个用户会话(Session)创建一个新的Bean实例。</p>
                    </div>
                    <ul class="text-gray-700 space-y-2 mb-4">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>适用于Web应用</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>跟踪用户会话状态</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>会话结束后实例被销毁</span>
                        </li>
                    </ul>
                    <div class="code-block p-4 text-sm overflow-x-auto">
                        @Component<br>
                        @Scope(value = WebApplicationContext.SCOPE_SESSION, <br>
                        &nbsp;&nbsp;proxyMode = ScopedProxyMode.TARGET_CLASS)
                    </div>
                </div>
                
                <!-- Global Session -->
                <div class="bg-white rounded-lg shadow-md p-6 scope-card transition-all duration-300">
                    <div class="icon-circle bg-red-500">
                        <i class="fas fa-users"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-center text-gray-800">Global Session (全局会话)</h3>
                    <div class="bg-red-50 p-4 rounded-lg mb-4">
                        <p class="text-red-800">Portlet环境中的全局会话范围。</p>
                    </div>
                    <ul class="text-gray-700 space-y-2 mb-4">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>仅适用于Portlet应用</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>类似Session作用域</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>在整个全局会话期间共享</span>
                        </li>
                    </ul>
                    <div class="code-block p-4 text-sm overflow-x-auto">
                        &lt;bean id="exampleBean" class="..." <br>
                        &nbsp;&nbsp;scope="globalSession"/&gt;
                    </div>
                </div>
                
                <!-- Custom -->
                <div class="bg-white rounded-lg shadow-md p-6 scope-card transition-all duration-300">
                    <div class="icon-circle bg-indigo-500">
                        <i class="fas fa-cogs"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-center text-gray-800">Custom (自定义)</h3>
                    <div class="bg-indigo-50 p-4 rounded-lg mb-4">
                        <p class="text-indigo-800">开发人员可以定义自己的作用域范围。</p>
                    </div>
                    <ul class="text-gray-700 space-y-2 mb-4">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>实现Scope接口</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>注册自定义作用域</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>满足特殊业务需求</span>
                        </li>
                    </ul>
                    <div class="code-block p-4 text-sm overflow-x-auto">
                        public class CustomScope implements Scope { ... }<br>
                        context.registerScope("custom", new CustomScope());
                    </div>
                </div>
            </div>
        </section>
        
        <!-- Practical Example -->
        <section class="mb-16 bg-white rounded-xl shadow-lg p-8 hover-grow">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">实际应用示例</h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-blue-600">XML配置方式</h3>
                    <div class="code-block p-4 text-sm overflow-x-auto">
                        &lt;!-- 单例作用域示例 --&gt;<br>
                        &lt;bean id="singletonBean" class="com.example.SingletonBean" <br>
                        &nbsp;&nbsp;scope="singleton"/&gt;<br><br>
                        
                        &lt;!-- 原型作用域示例 --&gt;<br>
                        &lt;bean id="prototypeBean" class="com.example.PrototypeBean" <br>
                        &nbsp;&nbsp;scope="prototype"/&gt;<br><br>
                        
                        &lt;!-- 请求作用域示例 --&gt;<br>
                        &lt;bean id="requestBean" class="com.example.RequestBean" <br>
                        &nbsp;&nbsp;scope="request"/&gt;
                    </div>
                </div>
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-purple-600">注解配置方式</h3>
                    <div class="code-block p-4 text-sm overflow-x-auto">
                        // 单例作用域(默认)<br>
                        @Service<br>
                        public class SingletonService { ... }<br><br>
                        
                        // 原型作用域<br>
                        @Repository<br>
                        @Scope("prototype")<br>
                        public class PrototypeDao { ... }<br><br>
                        
                        // 控制器示例<br>
                        @RestController<br>
                        @RequestMapping("/dept")<br>
                        @Scope("prototype")<br>
                        public class DeptController {<br>
                        &nbsp;&nbsp;@Autowired<br>
                        &nbsp;&nbsp;private IDeptService deptService;<br><br>
                        
                        &nbsp;&nbsp;@GetMapping<br>
                        &nbsp;&nbsp;public List&lt;Dept&gt; deptList() {<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;return deptService.list();<br>
                        &nbsp;&nbsp;}<br>
                        }
                    </div>
                </div>
            </div>
        </section>
        
        <!-- Best Practices -->
        <section class="bg-blue-50 rounded-xl p-8 mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">最佳实践建议</h2>
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <h3 class="text-xl font-semibold mb-3 flex items-center">
                        <i class="fas fa-lightbulb text-yellow-500 mr-2"></i>
                        <span>作用域选择原则</span>
                    </h3>
                    <ul class="text-gray-700 space-y-2">
                        <li class="flex items-start">
                            <i class="fas fa-check text-blue-500 mt-1 mr-2"></i>
                            <span>默认使用Singleton，适用于无状态服务</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-blue-500 mt-1 mr-2"></i>
                            <span>需要状态保持时使用Prototype</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-blue-500 mt-1 mr-2"></i>
                            <span>Web应用中用户相关数据使用Session</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-blue-500 mt-1 mr-2"></i>
                            <span>请求处理相关使用Request</span>
                        </li>
                    </ul>
                </div>
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <h3 class="text-xl font-semibold mb-3 flex items-center">
                        <i class="fas fa-exclamation-triangle text-red-500 mr-2"></i>
                        <span>注意事项</span>
                    </h3>
                    <ul class="text-gray-700 space-y-2">
                        <li class="flex items-start">
                            <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                            <span>Singleton中注入Prototype要注意代理问题</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                            <span>Web作用域(Request/Session)只能在Web环境中使用</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                            <span>Prototype作用域的Bean需要自行管理资源释放</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                            <span>注意线程安全问题，特别是Singleton作用域</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-10">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="text-center">
                <h3 class="text-xl font-semibold mb-2">技术小馆</h3>
                <p class="mb-4">分享前沿技术，传递开发智慧</p>
                <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition-colors" target="_blank">
                    <i class="fas fa-external-link-alt mr-1"></i>
                    http://www.yuque.com/jtostring
                </a>
            </div>
            <div class="border-t border-gray-700 mt-8 pt-8 text-center text-sm text-gray-500">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            themeVariables: {
                primaryColor: '#6e8efb',
                primaryBorderColor: '#4a6cf7',
                primaryTextColor: '#fff',
                lineColor: '#a777e3'
            }
        });
        
        // 添加卡片悬停效果
        document.querySelectorAll('.scope-card').forEach(card => {
            card.addEventListener('mouseenter', function() {
                this.style.transition = 'all 0.3s ease';
            });
        });
    </script>
</body>
</html>
```